package main

import (
	"fmt"
	"time"
)

func main() {
	now := time.Now()
	fmt.Printf("%T %v\n", now, now)
	fmt.Println("-----------------------------------------------")
	format := now.Format("2006-01-02 15:04:05.999") //15 24小时制
	fmt.Println(format)
	format = now.Format("2006-01-02 03:04:05.999") //03 12小时制
	fmt.Println(format)
	fmt.Println("-----------------------------------------------")

	unix := now.Unix()
	fmt.Println(unix)
	nano := now.UnixNano()
	fmt.Println(nano)
	fmt.Println("-----------------------------------------------")

	var timestamp int64 = 1724306303
	t := time.Unix(timestamp, 0)
	fmt.Println(t.Format("2006-01-02 15:04:05.999"))

	fmt.Println("-----------------------------------------------")
	str := "2024-08-22 13:58:23"
	location, _ := time.ParseInLocation("2006-01-02 15:04:05", str, time.Local)
	fmt.Println(location.Unix(), location.UnixMilli(), location.UnixMicro(), location.UnixNano())

	fmt.Println("-----------------------------------------------")
	fmt.Println(time.Nanosecond)
	fmt.Println(time.Microsecond)
	fmt.Println(time.Millisecond)
	fmt.Println(time.Second)

	fmt.Println("-----------------------------------------------")
	now = now.Add(time.Hour)
	fmt.Println(now.Format("2006-01-02 15:04:05.999"))
}
